package com.zhentao.product.controller;

import com.zhentao.model.entity.product.Category;
import com.zhentao.model.entity.product.ProductSku;
import com.zhentao.model.vo.common.Result;
import com.zhentao.model.vo.common.ResultCodeEnum;
import com.zhentao.model.vo.h5.IndexVo;
import com.zhentao.product.service.CategoryService;
import com.zhentao.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api("首页接口管理")
// @CrossOrigin(origins = "*")
@RestController
@RequestMapping("api/product/index")
public class IndexController {

    @Resource
    private CategoryService categoryService;
    @Resource
    private ProductService productService;

    /**
     * 首页初始化
     * @return
     */
    @ApiOperation(value = "首页初始化方式", notes = "", httpMethod = "GET")
    @GetMapping
    public Result<IndexVo> findData(){
        List<Category> categoryList = categoryService.findOneCategory();
        List<ProductSku> productSkuList = productService.findProductSkuBySale();
        IndexVo indexVo = new IndexVo() ;
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);
        return Result.build(indexVo , ResultCodeEnum.SUCCESS);
    }

}
